package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LsFile;
import com.ruoyi.system.service.ILsFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author zhouyipeng
 * @date 2023-11-06
 */

@RestController
@RequestMapping("/system/file")
public class LsFileController extends BaseController
{
    @Autowired
    private ILsFileService lsFileService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(LsFile lsFile)
    {
        startPage();
        List<LsFile> list = lsFileService.selectLsFileList(lsFile);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LsFile lsFile)
    {
        List<LsFile> list = lsFileService.selectLsFileList(lsFile);
        ExcelUtil<LsFile> util = new ExcelUtil<LsFile>(LsFile.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") String fileId)
    {
        return success(lsFileService.selectLsFileByFileId(fileId));
    }

    @PostMapping("/upload")
    public AjaxResult upload(@RequestBody LsFile lsFile)
    {
        if (StringUtils.isEmpty(lsFile.getFileBase64())){
            return error("文件base64字符串不可为空");
        }
         lsFile = lsFileService.insertByUpload(lsFile);
        return success(lsFile);
    }

    @GetMapping("/download")
    public AjaxResult download(@RequestParam("uuid") String uuid){

        return success(lsFileService.download(uuid));
    }


}
